#include "GSSaturday.h"
#include "GSDuelSelect.h"
#include "GSSunday.h"

GSSaturday::GSSaturday()
{
	SetStateName("GSSATURDAY");
	isDayStart = true;
}

GSSaturday::~GSSaturday()
{
	Game::GetDevice()->GetDriver()->removeTexture(sprSaturday);
}

void GSSaturday::OnEnter()
{
	PLAYER->m_isDoneRankChange = false;
	if(isDayStart)
	{
		isDayStart = false;
		Game::GetInstance()->GetPlayer()->UpdatePlayerStats();
	}
	fontCustom = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/fontcourier.bmp");
	fontCustom2 = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/mv_boli.png");
	fontCustomBig = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/bigfont.png");
	sprSaturday = Game::GetDevice()->GetDriver()->getTexture("data/sprites/sprSaturday.png");
	bgBox = core::rect<s32>(0,0, 1024, 600);
	isNoPoints = false;
	isNoHP = false;
}

void GSSaturday::OnExit()
{

}

void GSSaturday::Update()
{
	if(Game::GetDevice()->receiver.IsKeyUp(KEY_KEY_1))
	{
		if(PLAYER->GetHealthPoint() <= NULL)
			isNoHP = true;
		else if(Game::GetInstance()->GetPlayer()->GetCurrentDayPoints() < POINT_SUBTRACT_VALUE_MAIN)
		{
			isNoPoints = true;
		}
		else
		{
			Game::GetInstance()->GetPlayer()->SubCurrentDayPoints(POINT_SUBTRACT_VALUE_MAIN);
			Game::PushState((GameState*)new GSDuelSelect());
		}
	}
	else if(Game::GetDevice()->receiver.IsKeyUp(KEY_KEY_2))
	{
		Game::GetInstance()->NextDay();
		Game::SetState((GameState*)new GSSunday());
	}
}

void GSSaturday::Render()
{
	Game::GetDevice()->GetDriver()->beginScene(true, true, video::SColor(255,255,255,255));

	Game::GetDevice()->GetDriver()->draw2DImage(sprSaturday, core::position2di(0, 0), bgBox, 0, video::SColor(255,255,255,255), true);
	fontCustom->draw("1. Battle", core::rect<s32>(80, 300,100,10), video::SColor(255,0,0,0));
	fontCustom->draw("2. Go Home", core::rect<s32>(80, 312,100,10), video::SColor(255,0,0,0));
	if(isNoPoints)
		fontCustom2->draw("You Don't have enough Points!", core::rect<s32>(SCREEN_WIDTH/2 - 100, 330,100,10), video::SColor(255,255,0,0));
	if(isNoHP)
		fontCustom2->draw("You Don't Have HP to Fight!", core::rect<s32>(SCREEN_WIDTH/2 - 100, 350,100,10), video::SColor(255,255,0,0));
	Game::GetDevice()->GetDriver()->endScene();
}